You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
699 B
17 lines
699 B
import { getPostByPublicSlugAndSlugForViewer } from "#server/service/posts";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const publicSlug = event.context.params?.publicSlug;
|
|
const postSlug = event.context.params?.postSlug;
|
|
if (!publicSlug || !postSlug || typeof publicSlug !== "string" || typeof postSlug !== "string") {
|
|
throw createError({ statusCode: 400, statusMessage: "无效请求" });
|
|
}
|
|
|
|
const viewer = await event.context.auth.getCurrent();
|
|
const post = await getPostByPublicSlugAndSlugForViewer(publicSlug, postSlug, viewer?.id ?? null);
|
|
if (!post) {
|
|
throw createError({ statusCode: 404, statusMessage: "未找到" });
|
|
}
|
|
|
|
return R.success({ post });
|
|
});
|
|
|